package com.yixiu.study.juc.thread;

import java.util.concurrent.TimeUnit;

/**
 * @CalssName T01_whatIsThread
 * @Description
 * @Author yixiu
 * @Date 2021/6/23 19:12
 * @Verison num1.0
 **/
public class T01_whatIsThread {

    private static class T1 extends Thread {
        @Override
        public void run(){
            for(int i=0; i<10; i++){
                try {
                    TimeUnit.MICROSECONDS.sleep(1);
                } catch (InterruptedException e){
                    e.printStackTrace();
                }
                System.out.println("T1");
            }
        }
    }

    public static void main(String[] args) {
//        new T1().run();/*阻塞/挂起当前线程，先执行这个操作，执行结束后，才执行之前被挂起的线程*/
        new T1().start();/*开启新的线程，不阻塞，所以会交替、无规则打印T1、main*/
        for(int i=0; i<10; i++){
            try {
                TimeUnit.MICROSECONDS.sleep(1);
            } catch (InterruptedException e){
                e.printStackTrace();
            }
            System.out.println("main");
        }

    }

}
